package com.example.demo;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.pojo.CommonJSONResult;
import com.example.pojo.SysUser;
import com.utils.JsonUtils;

@RestController
@RequestMapping("/redis")
public class RedisController {
	@Autowired
	private StringRedisTemplate strRedisTemplate;
	
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	private static final String KEY_1 = "liuwenz is handsome";
	
	private static final String KEY_2 = "liuwenz is very handsome";
	
	private static final String KEY_3 = "liuwenz:very:handsome";
	@GetMapping("/test")
	public CommonJSONResult test() {
		strRedisTemplate.opsForValue().set(KEY_1, "这不是废话吗");
		strRedisTemplate.opsForHash().put(KEY_2, "name", "刘文钊非常的潇洒！！！");
		strRedisTemplate.opsForValue().set(KEY_3, JsonUtils.objectToJson(SysUser.builder().age(18).name("刘文钊大哥").createDate(new Date()).build()));
		
		return CommonJSONResult.ok(
				strRedisTemplate.opsForHash().get(KEY_2, "name") 
				+ strRedisTemplate.opsForValue().get(KEY_1) 
				+ JsonUtils.jsonToPojo(strRedisTemplate.opsForValue().get(KEY_3), SysUser.class).toString());
	}

}
